package com.beauty.payment.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Getter
public class AlipayConfig {
    // 支付宝沙箱网关
    private static final String GATEWAY_URL = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
    // 应用ID
    private static final String APP_ID = "9021000142601185";
    // 商户私钥
    private static final String MERCHANT_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCJBQQ7mkTGzgyT2261zMHP1EL78xSCWZuAmKkakebrZ/OpvYD4Kf8PuUX5TfoxxdTlZGbiIp/lbgvzmaXMo7WW3tgmG1uaa2G+fX5Q4x7wbnFpmj/Rzfb2qJUP7VtlOK7qIc/3NHSW4fg81ByEFTe25RJN333U4BYTaBnDila4EHTiuvfHvwMgcAT7xdulv24xMSaMwI/bMVQKoNvAf3OYVZk4XhOlTDauXQgux2ak/1i4IEXP7jh6JCxrf6oHNbcL/vZyDofnWxmaIIpbCU7Jfc65TUkp5IZyUduWrkQmNCqXwU0ll8+1iislmk0mW3jKCggRk/IKBWFQW/AM1v5VAgMBAAECggEAIU6p3785dsZBwnN17xWOC3JCsjI9yw3zQghaGw5afuDvF1Tsk+bJjM3x14+AATdg8D4+0DuweLoOh7HS3vLwwnL7QhAmbVwrD348BXegXrvKL+yCFQMnRIBoc820COAFjP6ZKjODH+ZgTJEXOXha6ce3clygnu22EBOfJ6xqNiXW5ddcs0G7rlKR8FaZtHQwf5gS3wbn1yDIXrTD5YNrnHJ9BtT6xRROZKkuBx87bR0bDffQ/Zhc7YwGr6sYThUk9O1G8Tu2J1C2EK2HeIIPr6TRe+fl5HDrtBdn9/Iv6cyv9YNdJ2T8c5FOYA9DVIJCmYoBr/a5mK/MAEHz+kVPYQKBgQC7snuOOUtXXR7wCZMU6PQ5xYnCsoRQ6SRwFdPg1mo1LicPn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06sdk26EIAlBkR5IsDrC8DqWXQLizaVMdT76IhIW8ElgAU2D1mj+F4LXWmDxbW2v4f84wvFz0Cei+oILSaes+zwwjoGUsC92SZ6wB9Yh7cxY8tKfpaHSUgaL2eTOv42n6jWuImVpog9CDtA51f1dhoHenG67dChw7qY3qrFYFuRpfMddwIDAQAB";
    private static final String CHARSET = "UTF-8";
    // 返回格式
    private static final String FORMAT = "json";
    // 签名方式
    private static final String SIGN_TYPE = "RSA2";
    
    // 服务器异步通知页面路径
    @Value("${alipay.notify-url:http://localhost:8080/api/payment/alipay/notify}")
    private String notifyUrl;
    
    // 页面跳转同步通知页面路径
    @Value("${alipay.return-url:http://localhost:9000/#/user/payment/result}")
    private String returnUrl;

    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(GATEWAY_URL, APP_ID, MERCHANT_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
    }
    
    /**
     * 获取签名类型
     */
    public String getSIGN_TYPE() {
        return SIGN_TYPE;
    }
    
    /**
     * 获取字符集
     */
    public String getCHARSET() {
        return CHARSET;
    }
    
    /**
     * 获取支付宝公钥
     */
    public String getALIPAY_PUBLIC_KEY() {
        return ALIPAY_PUBLIC_KEY;
    }
} 